<template>
  <div class="information">
    <el-select
      class="in-select"
      style="width: 97%"
      v-model="value"
      popper-class="in-list"
      @change="change"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <div class="in-Title">
      <div class="titlecolor"></div>
      <div class="in">
        <h1 class="intitle">{{ title }}</h1>
      </div>
    </div>
    <div class="in-content">
      <template v-if="show == 1">
        <li
          class="list-item-info"
          v-for="{ title, time, id } in build"
          :key="id"
          @click="article1(id)"
        >
          <p class="list-item-title">{{ title }}</p>
          <i class="arrow1 el-icon-arrow-right"></i>
          <span class="list-item-time">{{ time }}</span>
        </li>
      </template>
      <template v-if="show == 2">
        <li
          class="list-item-info"
          v-for="{ title, time, id } in plans"
          :key="id"
          @click="article2(id)"
        >
          <p class="list-item-title">{{ title }}</p>
          <i class="arrow1 el-icon-arrow-right"></i>
          <span class="list-item-time">{{ time }}</span>
        </li>
      </template>
      <template v-if="show == 3">
        <div>稍等...</div>
      </template>
      <template v-if="show == 4">
        <div class="article">
          <div>
            <template>
              <h2 class="article-news-title">
                {{ build[build.length - 1].title }}
              </h2>
              <div class="article-center">
                作者：
                {{ build[build.length - 1].author }}
                &ensp;
                {{ build[build.length - 1].time }}
                &ensp; 点击量：
                {{ build[build.length - 1].clicks }}
              </div>
              <hr />
              <iframe
                :src="build[build.length - 1].content"
                class="article-pdf"
                frameborder="0"
              ></iframe>
            </template>
          </div>
        </div>
      </template>
      <template v-if="show == 5">
        <div class="article">
          <div>
            <template>
              <h2 class="article-news-title">{{ plans[id - 1].title }}</h2>
              <div class="article-center">
                作者：
                {{ plans[plans.length - 1].author }}
                &ensp;
                {{ plans[plans.length - 1].time }}
                &ensp; 点击量：
                {{ plans[plans.length - 1].clicks }}
              </div>
              <hr />
              <iframe
                :src="plans[id - 1].content"
                class="article-pdf"
                frameborder="0"
              ></iframe>
            </template>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import { constitution, plan } from "@/api";
import Request from "@/api/request";
import Qs from "qs";
export default {
  name: "Information",
  data() {
    return {
      options: [
        { value: "1", label: "章程建设" },
        { value: "2", label: "学院十四五规划" },
        { value: "3", label: "校长信箱", link: "mailto:sdsyyzxx@163.com" },
      ],
      value: this.$route.query.key,
      title: this.$route.query.key,
      show: this.$route.query.show,
      id: this.$route.query.id,
      build: [],
      plans: [],
    };
  },
  created() {
    constitution().then((res) => {
      const constitution = res.data;
      this.build = constitution;
    });
    plan().then((res) => {
      const plan = res.data;
      this.plans = plan;
    });
  },
  mounted() {
    this.$emit("info1", false);
  },
  beforeDestroy() {
    this.$emit("info", true);
  },
  watch: {
    $route(to, from) {
      this.show = to.query.show;
      this.title = to.query.key;
      this.value = to.query.key;
      this.id = to.query.id;
    },
  },
  methods: {
    change(value) {
      let obj = {};
      obj = this.options.find((item) => {
        return item.value === value;
      });
      this.value = obj.label;
      this.title = this.value;
      this.$router.replace({
        query: { key: this.title, show: obj.value },
      });
      if (obj.value == 3) {
        window.location.href = obj.link;
      }
    },
    article1(id) {
      this.$router.push({
        query: { key: "章程建设", show: 4, id: id },
      });
      // 发送章程建设post请求
      Request({
        url: "/lookup/zcjs",
        method: "post",
        data: Qs.stringify({ page: 1 }),
        params: { id: id },
      }).then((res) => {
        // 同步更新点击量
        this.build[this.build.length - 1].clicks = res.data.clicks;
      });
    },
    article2(id) {
      this.$router.push({
        query: { key: "学院十四五规划", show: 5, id: id },
      });
      // 发送学院十四五规划post请求
      Request({
        url: "/lookup/ssw",
        method: "post",
        data: Qs.stringify({ page: 1 }),
        params: { id: id },
      }).then((res) => {
        // 同步更新点击量
        this.plans[this.plans.length - 1].clicks = res.data.clicks;
      });
    },
  },
};
</script>

<style>
/* 教学科研 */
.information {
  background: white;
  padding: 0.2rem;
}
/* 标题容器 */
.in {
  display: inline-block;
}
/* 内容容器 */
.in-content {
  margin-top: 0.72rem;
}
/* 列表 */
.list-item-info {
  list-style: none;
  line-height: 1rem;
  font-size: 0.56rem;
  padding-left: 0.4rem;
  padding-bottom: 0.36rem;
  border-bottom: 0.04rem dashed #eeeeee;
  margin-bottom: 0.72rem;
}
/* 列表标题 */
.list-item-information .list-item-title {
  width: 88%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 列表时间 */
.list-item-information .list-item-time {
  font-size: 0.4rem;
  color: #c3c3c3;
}
/* 选择栏容器 */
.in-list {
  text-align: center;
  background: rgba(0, 0, 0, 0.75);
}
/* 单个选择栏 */
.in-list .el-select-dropdown__item {
  color: white;
  border-bottom: 1px solid #868686;
  font-size: 0.6rem !important;
  height: auto !important;
  line-height: 1.5rem !important;
}
/* 最后一个选项框去掉底部边框线 */
.in-list .el-select-dropdown__item:last-child {
  border-bottom: 0;
}
/* 选择框选择栏选中后 */
.in-list .el-select-dropdown__item.hover {
  background-color: rgba(0, 0, 0, 0.75);
}
/* 上一条和下一条 */
.article .previous-next {
  font-size: 0.5rem;
}
/*  */
.article .previous-next p:last-child {
  padding-bottom: 0.72rem;
}
/* 文章中pdf */
.article-pdf {
  width: 90%;
  height: 19.2rem;
  margin-left: 0.8rem;
}
</style>
